#include<stdio.h>

char** generateParenthesis(int n, int* returnSize) {     	  	
    int ls = 0, rs = 0, i;
    char stack[2*n];
    int top = 0;
    char ** res = malloc(10000*sizeof(char*));
    (* returnSize) = 0;
    while (1) {     	  	
        if (top == 2 * n) {     	  	
            res[(* returnSize)] = malloc(top+1);
            for (i = 0 ; i < top ; i++) {     	  	
                res[(* returnSize)][i] = stack[i];
            }
            res[(* returnSize)][i] = '\0';
            (* returnSize)++;
            while (1) {     	  	
                if (top == 0) {     	  	
                    break;
                }
                while (stack[top-1] == ')') {     	  	
                    rs--;
                    top--;
                }
                // stack[top-1] == '('
                ls--;
                top--;
                if (ls <= rs) {     	  	
                    continue;
                } else {     	  	
                    stack[top++] = ')';
                    rs++;
                    break;
                }
            }
        }
        if ((* returnSize) != 0 && top == 0) {     	  	
            break;
        }
        if (ls < n) {     	  	
            stack[top++] = '(';
            ls++;
        } else {     	  	
            stack[top++] = ')';
            rs++;
        }
    }
    return res;
}     	  	
int main(int argc, char **argv)
{     	  	


    printf("Please input the number\n");
    int n;
    scanf("%d",&n);
    int returnSize,i;
    char** array = generateParenthesis( n,  &returnSize);
    printf("values are %d\n", returnSize);
    for (  i = 0; i < returnSize; ++i)
    {     	  	
        printf("%s\n", array[i]);
    }


}    